#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 1e3 + 10;
int arr[N], b[N];
LL l, r;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		memset(arr, 0, sizeof(arr));
		memset(b, 0, sizeof(b));
		cin >> l >> r;
		int cnt1 = 0, cnt2 = 0;
		while (l) {
			arr[cnt1++] = l % 2;
			l /= 2;
		}
		while (r) {
			b[cnt2++] = r % 2;
			r /= 2;
		}
		LL ans = 0;
		for (int i = max(cnt1, cnt2) - 1; i >= 0; i--) {
			if (arr[i] == b[i]) {
				if (b[i] == 1) {
					ans += (LL)pow(2, i);
				}
			}
			else {
				ans += (LL)pow(2, i + 1) - 1;
				break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}